package com.ctvit.breadking.news.website.controller;

import com.ctvit.breadking.news.website.pojo.dto.WebsiteDTO;
import com.ctvit.breadking.news.website.pojo.vo.WebsiteVO;
import com.ctvit.breadking.news.website.service.WebsiteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("website")
public class WebsiteController {

    private final WebsiteService websiteService;

    public WebsiteController(WebsiteService websiteService) {
        this.websiteService = websiteService;
    }

    @PostMapping("save")
    public boolean save(@RequestBody @Validated WebsiteDTO websiteDTO) {
        return websiteService.save(websiteDTO);
    }

    @PostMapping("delete")
    public boolean delete(@RequestParam String code) {
        return websiteService.delete(code);
    }

    @PostMapping("list")
    public List<WebsiteVO> list() {
        return websiteService.list();
    }

}
